package com.woniuxy.service.impl;

import com.woniuxy.dao.RbacRoleMenuDao;
import com.woniuxy.service.RbacRoleMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: mayuhang  <br/>
 * Date: 2021/4/29:12:03  <br/>
 * Description:
 */
@Service
public class RbacRoleMenuServiceImpl implements RbacRoleMenuService {
    @Autowired(required = false)
    RbacRoleMenuDao rbacMenuDao;

    @Override
    public int insertRoleMenu(int roleid,int[] menuid) {
//        roleid:4  menuid: [13, 14]
        List<Map<String,Integer>> collections = new ArrayList<>();
        for (int i:menuid) {
            Map<String,Integer> objectObjectHashMap = new HashMap<>();
            objectObjectHashMap.put("roleid",roleid);
            objectObjectHashMap.put("menuid",i);
            collections.add(objectObjectHashMap);
        }
        //collections:[{"roleid":4,"menuid":13},{"roleid":4,"menuid":14}]
        rbacMenuDao.deleteRole(roleid);
        return rbacMenuDao.insertBatch(collections);
    }

    @Override
    public List<Integer> findOneRole(int id) {
        return rbacMenuDao.findOneRole(id);
    }
}
